home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / sdi / genmessa.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-18  |  2.5 KB  |  102 lines

  1. #include <pixrect/pixrect_hs.h>
  2. #define NULL 0
  3.  
  4. /*
  5.  * Copyright 1987 by Mark Weiser.
  6.  * Permission to reproduce and use in any manner whatsoever on Suns is granted
  7.  * so long as this copyright and other identifying marks of authorship
  8.  * in the code and the game remain intact and visible.  Use of this code
  9.  * in other products is reserved to me--I'm working on Mac and IBM versions.
  10.  */
  11.  
  12. /*
  13.  * Real quick and dirty hack to enlarge an image.  Reads and outputs
  14.  * in C-style pixrect form (human readable, #includable).  Takes
  15.  * two arguments: the file to be enlarged, and the integer enlargement.
  16.  *
  17.  * This is not used during the game itself (too slow), but run at
  18.  * 'make' time to constuct the popup face for the end of game.
  19.  */
  20. short *in;
  21. /* size of input image */
  22. #define SIZE 64
  23. /* how much larger to make each dimension */
  24. #define MAXMULT 16
  25. int MULT;
  26.  
  27. /*
  28.  * The theory is, by changing only 'pattern' and 'shift' to reflect the
  29.  * bit numbering of the target machine, this code will work for big
  30.  * and little endians.
  31.  */
  32.  
  33. static short pattern[] = {
  34.     0x8000, 0x4000, 0x2000, 0x1000, 0x800, 0x400, 0x200, 0x100,
  35.     0x80,   0x40,   0x20,   0x10,   0x8,   0x4,   0x2,   0x1
  36.     };
  37.  
  38. static short shift[] = {
  39.     15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
  40.     };
  41.  
  42. static short out[SIZE*SIZE*MAXMULT*MAXMULT/16 + 1];
  43.  
  44.  
  45. main(argc, argv)
  46. char **argv;
  47. {
  48.     int row, col, val, i, j;
  49.     struct pixrect *pr, *icon_load_mpr();
  50.  
  51.     char error_msg[256];
  52.     if (argc != 3) {
  53.         printf("Usage: genmessage file factor\n");
  54.         exit(1);
  55.     }
  56.     argc--; argv++;
  57.     if ((pr = icon_load_mpr(*argv, error_msg)) == NULL) {
  58.         printf("Could not get file '%s'.\n", *argv);
  59.         printf("%s",error_msg);
  60.     }
  61.     in = mpr_d(pr)->md_image;
  62.  
  63.     argc--; argv++;
  64.     MULT = atol(*argv);
  65.     if (MULT > MAXMULT) {
  66.         printf("Factor too big.\n");
  67.         exit(1);
  68.     }
  69.  
  70.     printf("/* Format_version=1, Width=%d, Height=%d, Depth=1, Valid_bits_per_item=16\n */\n", SIZE*MULT, SIZE*MULT);
  71.     for (row = 0; row < SIZE; row++) {
  72.         for (col = 0; col < SIZE; col++) {
  73.             val = bitval(in, row*SIZE + col);
  74.             for (i=0; i<MULT; i++)
  75.                 for (j=0; j<MULT; j++)
  76.                     bitset(out, row*MULT*MULT*SIZE+(MULT*SIZE*i) + col*MULT+j, val);
  77.             }
  78.     }
  79.     for (i = 0; i < SIZE*SIZE*MULT*MULT/128; i++) {
  80.         for ( j = 0;  j < 8; j++) {
  81.             printf(" 0x%04x, ", out[i*8 + j] & 0xffff);
  82.         }
  83.         printf("\n");
  84.     }
  85.     exit(0);
  86. }
  87.  
  88.  
  89. /* Machine-dependent: depends on what kind of endian. */
  90.  
  91. bitset(b, l, v)
  92. short *b;
  93. {
  94.     b[l/16] = b[l/16] & ~pattern[l%16] | (((v & 0x1) << shift[l%16]) & pattern[l%16]);
  95. }
  96.  
  97. bitval(b, l)
  98. short *b;
  99. {
  100.     return ((b[l/16] & pattern[l%16]) >> shift[l%16]) & 0x1;
  101. }
  102.